/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.zcm.modules.cxf.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.zcm.common.config.Global;
import com.zcm.common.persistence.Page;
import com.zcm.common.web.BaseController;
import com.zcm.common.utils.StringUtils;
import com.zcm.modules.cxf.entity.CxfSession;
import com.zcm.modules.cxf.service.CxfSessionService;

/**
 * ws会话控制Controller
 * @author wangwenwei
 * @version 2018-07-28
 */
@Controller
@RequestMapping(value = "${adminPath}/cxf/cxfSession")
public class CxfSessionController extends BaseController {

	@Autowired
	private CxfSessionService cxfSessionService;
	
	@ModelAttribute
	public CxfSession get(@RequestParam(required=false) String id) {
		CxfSession entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = cxfSessionService.get(id);
		}
		if (entity == null){
			entity = new CxfSession();
		}
		return entity;
	}
	
	@RequiresPermissions("cxf:cxfSession:view")
	@RequestMapping(value = {"list", ""})
	public String list(CxfSession cxfSession, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<CxfSession> page = cxfSessionService.findPage(new Page<CxfSession>(request, response), cxfSession); 
		model.addAttribute("page", page);
		return "modules/cxf/cxfSessionList";
	}

	@RequiresPermissions("cxf:cxfSession:view")
	@RequestMapping(value = "form")
	public String form(CxfSession cxfSession, Model model) {
		model.addAttribute("cxfSession", cxfSession);
		return "modules/cxf/cxfSessionForm";
	}

	@RequiresPermissions("cxf:cxfSession:edit")
	@RequestMapping(value = "save")
	public String save(CxfSession cxfSession, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, cxfSession)){
			return form(cxfSession, model);
		}
		cxfSessionService.save(cxfSession);
		addMessage(redirectAttributes, "保存会话成功");
		return "redirect:"+Global.getAdminPath()+"/cxf/cxfSession/?repage";
	}
	
	@RequiresPermissions("cxf:cxfSession:edit")
	@RequestMapping(value = "delete")
	public String delete(CxfSession cxfSession, RedirectAttributes redirectAttributes) {
		cxfSessionService.delete(cxfSession);
		addMessage(redirectAttributes, "删除会话成功");
		return "redirect:"+Global.getAdminPath()+"/cxf/cxfSession/?repage";
	}

}